package tx.os3.clientserver.client.model;

import java.util.Observable;
import java.util.Observer;

/**
 * Default implementation of the {@link ServerModel} interface.
 * 
 * @author Thomas Middeldorp
 */
public class DefaultServerModel extends Observable implements ServerModel {

    private ServerStatus status;
    private String serverInfo;

    @Override
    public ServerStatus getStatus() {
        return this.status;
    }

    @Override
    public void setStatus(ServerStatus status) {
        if(status == null) {
            throw new IllegalArgumentException("Status cannot be null.");
        }
        this.status = status;
        this.notifyObserver();
    }

    @Override
    public String getServerInfo() {
        return this.serverInfo;
    }

    @Override
    public void setServerInfo(String serverInfo) {
        if(serverInfo == null) {
            throw new IllegalArgumentException("ServerInfo cannot be null.");
        }
        this.serverInfo = serverInfo;
        this.notifyObserver();
    }

    /**
     * Wrapper method to notify observers.
     */
    private void notifyObserver() {
        this.setChanged();
        this.notifyObservers();
    }

    @Override
    public synchronized void addObserver(Observer o) {
        super.addObserver(o);
        this.notifyObserver();
    }
}
